package com.platform.api;

import com.alibaba.fastjson.JSONObject;
import com.platform.annotation.LoginUser;
import com.platform.entity.SysParameterVo;
import com.platform.entity.UserVo;
import com.platform.service.ApiSysParameterService;
import com.platform.util.ApiBaseAction;
import com.platform.utils.RRException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者: @author zzh <br>
 * 时间: 2018-11-29 08:32<br>
 * 描述: 系统参数接口 <br>
 */
@Api(tags = "参数管理")
@RestController
@RequestMapping("/api/parameters")
public class ApiParameterController  extends ApiBaseAction {
    @Autowired
    ApiSysParameterService sysParameterService;
    /**
     * 查找系统参数
     */
    @ApiOperation(value = "查找系统参数")
    @RequestMapping(value = "getParameter")
    public Object getParameter(@LoginUser UserVo loginUser) {
        try{
            System.out.println("===================请求系统参数");
            JSONObject jsonParams = getJsonRequest();
            String parameter = jsonParams.getString("parameter");
            Map params = new HashMap();
            params.put("nideshop_user", loginUser.getUserId());
            params.put("parameter", parameter);
            //查询列表数据
            List<SysParameterVo> parameterVos = sysParameterService.queryList(params);
            if(parameterVos.size()==0){
                return toResponsFail("参数为空");
            }
            return toResponsSuccess(parameterVos.get(0));
        }catch(Exception e){
            e.printStackTrace();
            throw new RRException("查询失败"+e.getMessage());
        }
    }

}
